<?php

namespace common\jobs\spread;

use Yii;
use common\jobs\base\IntervalRetryableJob;
use common\jobs\handle\JoinBranchHandle;

/**
 * 加入会员下级分销
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class JoinBranchJob extends IntervalRetryableJob {

    /**
     * @var string 用户手机号
     */
    public $mobile = null;

    /**
     * @var integer|null 用户ID
     */
    public $user_id = null;

    /**
     * @param \yii\queue\Queue
     * @inheritdoc
     */
    public function execute($queue) {
        $model = new JoinBranchHandle();
        $model->mobile = $this->mobile;
        $model->user_id = $this->user_id;
        $model->job = $this;
        return $model->save();
    }

    /**
     * 间隔时间缓存ID
     * @inheritdoc
     */
    public function getUniqueCacheId() {
        return static::class . '_' . $this->user_id;
    }

}
